<template>
<div>



<el-card class="box-card" style="margin-top:150px;">
	<div slot="header" >
    	{{$route.params.name}}
	</div>

	<el-form ref="form" :model="form">
		<el-form-item >
			<el-input placeholder="票码" v-model="form.code" >
			    <el-button slot="append" icon="el-icon-setting" @click="openQRCode"></el-button>
			</el-input>
		</el-form-item>

	  	<el-form-item >
	    	<el-button type="primary" @click="gogo" style="width:100%">核销</el-button>
	  	</el-form-item>

	  	<el-form-item >
	    	<el-button @click="gogo" style="width:100%">核销统计</el-button>
	  	</el-form-item>


	</el-form>
</el-card>


</div>
</template>

<script>

import { mapGetters } from 'vuex'
import wx from '../../config/weixin'

export default {
	
	name : 'destroymain',
	
	data () {
		return {
		  	form : {
		  		code : '',
		  	}
		}
	},

	props : {

	},

	components : {
		
	},

	computed : {
		...mapGetters([
			
		]),
	},

	methods : {
		gogo () {

			console.log('gogog');
			let para = {
				fun : 'queryByCode',
				code : this.form.code,
				device : this.$route.params.devicecode,
				cb : res => {
					console.log(res);

					this.$confirm('确认要核销这个票码吗?', '提示', {
			          confirmButtonText: '确定',
			          cancelButtonText: '取消',
			          type: 'warning'
			        }).then(() => {
			          	let para1 = {
							fun : 'destroyByCode',
							code : this.form.code,
							device : this.$route.params.devicecode,
							num : 1,
							reqkey : res.reqkey,
							cb : res1 => {
								console.log(res1);

								this.$message({
						          message: '核销成功',
						          type: 'success'
						        });
							},
							err : res1 => {
								this.$message.error(res1);
							}
						};

						this.$store.dispatch('update', para1);
			        }).catch(() => {
			                   
			        });
				},
				err : res => {
					this.$message.error(res);
				}
			};

			this.$store.dispatch('update', para);
			
		},


		openQRCode () {
			wx.wexinQRCode(res => {

				this.form.code = res;
			});
		}
	},

	watch : {
	    
	},

	mounted () {
		
	},

}
</script>

<style>
body {
	background-color: #fff;
}
</style>
